package com.yangjun.dao.impl.realtimeLiveAnalysis.realtimeSituation;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mapping.model.CamelCaseSplittingFieldNamingStrategy;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yangjun.common.ownplatform.LineChart;
import com.yangjun.common.ownplatform.LineChartID;
import com.yangjun.dao.IRealTimeOverview;
import com.yangjun.entity.realtimeliveAnalysis.PurchaseSupplyEntity;
import com.yangjun.entity.realtimeliveAnalysis.RealTimeOverviewEntity;

/*
 * Brief: 自建平台模型类
 */
@Repository
public class OwnPlatformImpl {
	
	 @Autowired
	 @Resource(name = "bikadJdbcTemplate")
	 private JdbcTemplate mJdbcTemplate;
	 
	 public List<Map<String, Object>> getPlatform() {
		 String sql = "select distinct(ordersource), "
		 		+ "sourcename "
		 		+ "from DV_DW_KAD_LIVE_OVERVIEW where ordersource in(1,13,14,15,21) order by ordersource ";
		 
		 return mJdbcTemplate.queryForList(sql);
	 }
	 
	  /*
	   * Brief：获取自建平台的总览数据
	   */
	   public List<Map<String, Object>> getOverviewData(String today,String yestoday, String contrastday, List<String> ordersources) {
		   String sql = "select to_char(data_date, 'YYYY-MM-DD') as data_date,sum(pv) as pvCnt, "
		   		+ "sum(VISIT_CNT) as visitCnt, "
		   		+ "trunc(sum(ORDER_AMOUNT)) as sale, "
		   		+ "sum(ORDER_CNT) as orderCnt, "
		   		+ "sum(CUS_CNT) as cusCnt, "
		   		+ "sum(ONLINE_ASK_CNT) as networkConsultCnt, "
		   		+ "sum(CALL_400_CNT) as phoneConsultCnt, "
		   		+ "sum(REGISTER_CNT) as registerCnt, "
		   		+ "trunc(sum(NOPAY_AMOUNT)) as nopayAmount, "
		   		+ "sum(NOPAY_ORDER_CNT) as nopayOrderCnt, "
		   		+ "case when sum(order_cnt)=0 then 0 else trunc(sum(order_amount) / sum(order_cnt)) end as orderAveragePrice, "
		   		+ "sum(OLD_VISIT_CNT) as oldVisitCnt, "
		   		+ "trunc(sum(OLD_CUS_AMOUNT)) as oldCusAmount, "
		   		+ "sum(OLD_ORDER_CNT) as oldOrderCnt, "
		   		+ "sum(OLD_CUS_CNT) as oldCusCnt "
		   		+ "from DV_DW_KAD_LIVE_OVERVIEW where data_date in(date'" + contrastday + "', date'" + yestoday + "', date'" + today + "') "
		   		+ "and ordersource in(:ordersources) "
		   		+ "group by data_date order by data_date";
	    	
		   NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(mJdbcTemplate);
		   MapSqlParameterSource parameters = new MapSqlParameterSource();
		   parameters.addValue("ordersources", ordersources);
		    
	       List<Map<String,Object>> rows = namedParameterJdbcTemplate.queryForList(sql, parameters);
	        
	       return rows;
	    }
	   
	   
	   public List<Map<String, Object>> getOutStockWaresSummary(String today, String contrastday, List<String> ordersources) {
		   String sql = "select count(distinct warecode) as wareCnt, "
				+ "sum(a.IMPACT_QTY) as outStockTotalCnt, "
		   		+ "sum(a.IMPACT_AMOUNT) as sale "
				+ "from dv_dw_kad_live_ware_outstock a where "
				+ "data_date in(date'" + today + "', date'" + contrastday + "') "
				+ "group by a.data_date ";
		   
		   NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(mJdbcTemplate);
		   MapSqlParameterSource parameters = new MapSqlParameterSource();
		   parameters.addValue("ordersources", ordersources);
			    
		   List<Map<String,Object>> rows = namedParameterJdbcTemplate.queryForList(sql, parameters);
		        
		   return rows;
	   }
	   
	   // ---------------- 退款 ----------------
	   public List<Map<String, Object>> getRefund(String today, String contrastday, List<String> ordersources) {
		   String sql = "select a.data_date as data_date, "
		   		+ "sum(a.REFUND_ORDER_CNT) as refundOrderCnt, "
		   		+ "trunc(sum(a.REFUND_AMOUNT)) as refundAmount, "
		   		+ "sum(a.DOWN_REFUND_CNT) as downRefundCnt "
				+ "from DV_DW_KAD_LIVE_OVERVIEW a where "
		   		+ "a.ORDERSOURCE in (:ordersources) "
				+ "and data_date in(date'" + today + "', date'" + contrastday + "') "
				+ "group by a.data_date ";
		   
		   NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(mJdbcTemplate);
		   MapSqlParameterSource parameters = new MapSqlParameterSource();
		   parameters.addValue("ordersources", ordersources);
			    
		   List<Map<String,Object>> rows = namedParameterJdbcTemplate.queryForList(sql, parameters);
		        
		   return rows;
	   }
	   
	   // ---------------- 物流 ---------------- 
	   public List<Map<String, Object>> getLogistics(String today, String contrastday, List<String> ordersources) {
		   String sql = "select sum(a.ORDER_CNT) as totalOrderCnt, "
		   		+ "sum(a.NOSYN_ORDER_CNT) as nosynConsignCnt, "
		   		+ "sum(a.DEAL_CONSIGN_CNT) as dealConsignCnt, "
		   		+ "sum(a.CONSIGN_OUT_CNT) as consignOutCnt, "
		   		+ "sum(a.COLLECT_CONSIGN_CNT) as collectConsignCnt, "
		   		+ "sum(a.NOCOLLECT_CONSIGN_CNT) as nocollectConsignCnt "
				+ "from DV_DW_KAD_LIVE_OVERVIEW a where "
		   		+ "a.ORDERSOURCE in (:ordersources) "
				+ "and a.data_date in(date'" + today + "') "
				+ "group by a.data_date ";
		   
		   NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(mJdbcTemplate);
		   MapSqlParameterSource parameters = new MapSqlParameterSource();
		   parameters.addValue("ordersources", ordersources);
			    
		   List<Map<String,Object>> rows = namedParameterJdbcTemplate.queryForList(sql, parameters);
		        
		   return rows;
	   }
	    
	    /*
	     * Brief: 获取销售额（柱状图）
	     */
	    public Map<String, Object> getSalesAmount(String date, List<String> ordersources) {
	        Map<String, Object> resultMap = Maps.newHashMap();
	        String sql =" select trunc(sum(ORDER_AMOUNT)) as amount,"
	        		+ "d.SOURCENAME as platform "
	        		+ "from DV_DW_KAD_LIVE_OVERVIEW d "
	        		+ "where d.DATA_DATE=date'"+date+"' "
	        		+ "and d.ordersource in (:ordersources) group by d.SOURCENAME order by trunc(sum(ORDER_AMOUNT)) desc";
	        
	        // Query
	        NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(mJdbcTemplate);
			MapSqlParameterSource parameters = new MapSqlParameterSource();
			parameters.addValue("ordersources", ordersources);
	        List<Map<String,Object>> queryList = namedParameterJdbcTemplate.queryForList(sql, parameters);
	        
	        // 柱状图数据
	        String[] amountArr = new String[queryList.size()];
	        String[] platformArr = new String[queryList.size()];
	        for(int i=0, len=queryList.size(); i<len; i++) {
	            amountArr[i] = String.valueOf(queryList.get(i).get("amount"));
	            platformArr[i] = String.valueOf(queryList.get(i).get("platform"));
	            
	            if(platformArr[i].equals("IPhone"))
	            	platformArr[i] = "IOS";
	        }
	        resultMap.put("value", amountArr);
	        resultMap.put("platform", platformArr);
	        
	        return  resultMap;
	    }
	    
	    // 没用？
	    public Map<String, Object> getChannelVisitCnt(String date) {
	        Map<String,Object> resultMap = Maps.newHashMap();
	        
	        String sql = "select trunc(sum(CLIENT_NUMBER)) as clientNumber, d.UTM_MEDIUM as utmMedium from Dv_Live_Chann_ClientNum d where d.DATE_DAY=date'"+date+"' and d.SITE_ID in (1,13,14,15,21)  group by d.DATE_DAY, d.UTM_MEDIUM ";	                
	        
	        List<Map<String,Object>> queryList = mJdbcTemplate.queryForList(sql);
	        
	        String[] amountArr = new String[queryList.size()];
	        String[] platformArr = new String[queryList.size()];
	        
	        for(int i=0, len=queryList.size(); i<len; i++) {
	            amountArr[i] = String.valueOf(queryList.get(i).get("金额"));
	            String platformName = String.valueOf(queryList.get(i).get("平台"));
	            if("IPhone".equals(platformName)) {
	            	platformName = "IOS";
	            }
	            platformArr[i] = platformName;
	        }
	        resultMap.put("value", amountArr);
	        resultMap.put("platform", platformArr);
	        
	        return  resultMap;
	    }
	    
	    /*
		 * Brief: 获取销售额比例数据（饼状图）
		 */
	    public Map<String,Object> getSaleProportion(String date, List<String> ordersources) {
	        Map resultMap = Maps.newHashMap();
	        List<Map<String,String>> list = Lists.newArrayList();
	         	               
	        String sql = " select trunc(sum(ORDER_AMOUNT)) as totalAmount, "
	        		+ "d.SOURCENAME as platform "
	        		+ "from DV_DW_KAD_LIVE_OVERVIEW d "
	        		+ "where d.DATA_DATE=date'" + date + "' "
	        		+ "and d.ordersource in (:ordersources) "
	        		+ "group by d.SOURCENAME";
	        
	        // Query
	        NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(mJdbcTemplate);
			MapSqlParameterSource parameters = new MapSqlParameterSource();
			parameters.addValue("ordersources", ordersources);
	        List<Map<String,Object>> queryList = namedParameterJdbcTemplate.queryForList(sql, parameters);
	        
	        // 饼图数据
	        String[] legendArr = new String[queryList.size()];
	        for(int i=0, len=queryList.size(); i<len; i++) {
	        	String platformName = String.valueOf(queryList.get(i).get("platform"));
	            if("IPhone".equals(platformName))
	            	platformName = "IOS";
	            
	            legendArr[i] = String.valueOf(platformName);
	            
	            Map<String,String> map = Maps.newHashMap();
	            map.put("value",String.valueOf(queryList.get(i).get("totalAmount")));
	            map.put("name",String.valueOf(platformName));
	            list.add(map);
	        }
	        resultMap.put("data", list);
	        resultMap.put("legend", legendArr);
	        
	        return  resultMap;
	    }
	
	/*
	 * Brief: 获取缺货销售额比例数据（饼状图）
	 */
	public Map<String, Object> getOutStockTotalAmt(String date, List<String> ordersources) {
		Map<String,Object> resultMap = Maps.newHashMap();
		System.out.println("date = " + date);
		
        String sql = "select a.employee as employee, "
        		+ "trunc(sum(a.IMPACT_AMOUNT)) as outstockOrderAmt "
        		+ "from dv_dw_kad_live_ware_outstock a where a.data_date=date'" + date + "' "
        		+ "group by a.employee order by outstockOrderAmt desc";
        
        // Query
        NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(mJdbcTemplate);
		MapSqlParameterSource parameters = new MapSqlParameterSource();
		parameters.addValue("ordersources", ordersources);
        List<Map<String,Object>> queryList = namedParameterJdbcTemplate.queryForList(sql, parameters);
        
        // 饼图数据
        List<Map<String,String>> dataList = Lists.newArrayList();
        String[] legendArr = new String[queryList.size()];
        
        for(int i=0, len=queryList.size(); i<len; i++) {
            legendArr[i] = String.valueOf(queryList.get(i).get("employee"));
            
            Map<String,String> map = Maps.newHashMap();
            map.put("value",String.valueOf(queryList.get(i).get("outstockOrderAmt")));
            map.put("name",String.valueOf(queryList.get(i).get("employee")));
            dataList.add(map);
        }
        resultMap.put("data", dataList);
        resultMap.put("legend", legendArr);
        
        return  resultMap;
	}
	
	public List<Map<String,Object>> getLineChartData(LineChartID id, String today, String contrastday, List<String> ordersources) {
		List<Map<String,Object>> rows = null;
		String sql = "";
		
		switch (id) {
		case sale:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(sum(ORDER_AMOUNT),0) as sale "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			System.out.println("sale=="+sql);
			break;
			
		case OrderCnt:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(sum(ORDER_CNT),0) as orderCnt "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case VisitCnt:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(sum(VISIT_CNT),0) as visitCnt "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case ConvertRatio:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(case when sum(VISIT_CNT) = 0 then 0 else sum(ORDER_CNT) / sum(VISIT_CNT) end, 4) as convertRatio "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case RegCustomerRatio:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(case when sum(CUS_CNT) = 0 then 0 else sum(OLD_CUS_CNT) / sum(CUS_CNT) end, 4) as regCustomerRatio "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case PayOnDeliveryRatio:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(case when sum(ORDER_CNT) = 0 then 0 else sum(CASH_ORDER_CNT) / sum(ORDER_CNT) end, 4) as payOnDeliveryRatio "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
		
//		case CusCnt:
//			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
//					+ "d.DATA_HOUR as dataHour, "
//					+ "round(sum(CUS_CNT),0) as cusCnt "
//					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
//					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
//					+ "and d.ordersource in (:ordersources) "
//					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
//			break;
			
		case NetworkConsultCnt:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(sum(ONLINE_ASK_CNT),0) as networkConsultCnt "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case PhoneConsultCnt:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(sum(CALL_400_CNT),0) as phoneConsultCnt "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case RegisterCnt:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(sum(DEMAND_REGISTER_CNT),0) as registerCnt "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case PreOrderCnt:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(sum(REGISTER_CNT),0) as preOrderCnt "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case ConsignOutCnt:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(sum(CONSIGN_OUT_CNT),0) as consignOutCnt "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case ConsignDeliverCnt:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "round(sum(CONSIGN_DELIVER_CNT),0) as consignDeliverCnt "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case PickCnt:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "sum(SYN_CONSIGN_CNT) - sum(NOPICK_CONSIGN_CNT) as pickCnt "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case RefundOrderCnt:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "sum(REFUND_ORDER_CNT) as refundOrderCnt "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;
			
		case RefundOrderHandleCnt:
			sql = "select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate, "
					+ "d.DATA_HOUR as dataHour, "
					+ "sum(DOWN_REFUND_CNT) as refundOrderHandleCnt "
					+ "from DV_DW_KAD_LIVE_OVERVIEW d "
					+ "where d.DATA_DATE in (date'"+today+"', date'"+contrastday+"') "
					+ "and d.ordersource in (:ordersources) "
					+ "group by d.DATA_DATE, d.DATA_HOUR order by d.DATA_DATE, d.DATA_HOUR";
			break;

		default:
			break;
		}
		
		// Query
		if (!sql.isEmpty()) {
			NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(mJdbcTemplate);
			MapSqlParameterSource parameters = new MapSqlParameterSource();
			parameters.addValue("ordersources", ordersources);
	        rows = namedParameterJdbcTemplate.queryForList(sql, parameters);
		}
        
        return rows;
	}
	
	
//	/*
//	 * Brief：获取销售额
//	 */
//	public List<Map<String,Object>> getSale(String today, String contrastday) {
//	      List<Map<String,Object>> rows = mJdbcTemplate.queryForList("select to_char(d.DATA_DATE,'YYYY-MM-DD') as dataDate,d.DATA_HOUR as dataHour,round(sum(TOTAL_AMOUNT),0) as sale from DV_DW_KAD_LIVE_OVERVIEW d where d.DATA_DATE in (date'"+today+"',date'"+contrastday+"') and d.ordersource in (1,13,14,15,21) group by d.DATA_DATE,d.DATA_HOUR order by d.DATA_DATE,d.DATA_HOUR");
//	      return rows;
//	}
//	
//	/*
//	 * Brief：获取订单数
//	 */
//	public List<Map<String,Object>> getOrderCnt(String today, String contrastday) {
//	      List<Map<String,Object>> rows = mJdbcTemplate.queryForList("select to_char(d.DATA_DATE,'YYYY-MM-DD') as dataDate,d.DATA_HOUR as dataHour,round(sum(order_amount),0) as orderCnt from DV_DW_KAD_LIVE_OVERVIEW d where d.DATA_DATE in (date'"+today+"',date'"+contrastday+"') and d.ordersource in (1,13,14,15,21) group by d.DATA_DATE,d.DATA_HOUR order by d.DATA_DATE,d.DATA_HOUR");
//	      return rows;
//	}
//	
//	/*
//	 * Brief：获取访客数
//	 */
//	public List<Map<String,Object>> getVisitCnt(String today, String contrastday) {
//	      List<Map<String,Object>> rows = mJdbcTemplate.queryForList("select to_char(d.DATA_DATE,'YYYY-MM-DD') as dataDate,d.DATA_HOUR as dataHour,round(sum(VISIT_CNT),0) as visitCnt from DV_DW_KAD_LIVE_OVERVIEW d where d.DATA_DATE in (date'"+today+"',date'"+contrastday+"') and d.ordersource in (1,13,14,15,21) group by d.DATA_DATE,d.DATA_HOUR order by d.DATA_DATE,d.DATA_HOUR");
//	      return rows;
//	}
//	
//	/*
//	 * Brief：获取买家数
//	 */
//	public List<Map<String,Object>> getCusCnt(String today, String contrastday) {
//	      List<Map<String,Object>> rows = mJdbcTemplate.queryForList("select to_char(d.DATA_DATE,'YYYY-MM-DD') as dataDate,d.DATA_HOUR as dataHour,round(sum(CUS_CNT),0) as cusCnt from DV_DW_KAD_LIVE_OVERVIEW d where d.DATA_DATE in (date'"+today+"',date'"+contrastday+"') and d.ordersource in (1,13,14,15,21) group by d.DATA_DATE,d.DATA_HOUR order by d.DATA_DATE,d.DATA_HOUR");
//	      return rows;
//	}
//	
//	/*
//	 * Brief：获取在线咨询客户数
//	 */
//	public List<Map<String,Object>> getNetworkConsultCnt(String today, String contrastday) {
//	      List<Map<String,Object>> rows = mJdbcTemplate.queryForList("select to_char(d.DATA_DATE,'YYYY-MM-DD') as dataDate,d.DATA_HOUR as dataHour,round(sum(ONLINE_ASK_CNT),0) as networkConsultCnt from DV_DW_KAD_LIVE_OVERVIEW d where d.DATA_DATE in (date'"+today+"',date'"+contrastday+"') and d.ordersource in (1,13,14,15,21) group by d.DATA_DATE,d.DATA_HOUR order by d.DATA_DATE,d.DATA_HOUR");
//	      return rows;
//	}
//	
//	/*
//	 * Brief：获取400接电数
//	 */
//	public List<Map<String,Object>> getPhoneConsultCnt(String today, String contrastday) {
//	      List<Map<String,Object>> rows = mJdbcTemplate.queryForList("select to_char(d.DATA_DATE,'YYYY-MM-DD') as dataDate,d.DATA_HOUR as dataHour,round(sum(CALL_400_CNT),0) as phoneConsultCnt from DV_DW_KAD_LIVE_OVERVIEW d where d.DATA_DATE in (date'"+today+"',date'"+contrastday+"') and d.ordersource in (1,13,14,15,21) group by d.DATA_DATE,d.DATA_HOUR order by d.DATA_DATE,d.DATA_HOUR");
//	      return rows;
//	}
//	
//	/*
//	 * Brief：出库包裹数
//	 */
//	public List<Map<String,Object>> getConsignOutCnt(String today, String contrastday) {
//	      List<Map<String,Object>> rows = mJdbcTemplate.queryForList("select to_char(d.DATA_DATE,'YYYY-MM-DD') as dataDate, d.DATA_HOUR as dataHour, round(sum(CONSIGN_OUT_CNT),0) as consignOutCnt from DV_DW_KAD_LIVE_OVERVIEW d where d.DATA_DATE in (date'"+today+"',date'"+contrastday+"') and d.ordersource in (1,13,14,15,21) group by d.DATA_DATE,d.DATA_HOUR order by d.DATA_DATE,d.DATA_HOUR");
//	      return rows;
//	}
//	
//	/*
//	 * Brief：拣货包裹数
//	 */
//	public List<Map<String,Object>> getPickCnt(String today, String contrastday) {
//	      List<Map<String,Object>> rows = mJdbcTemplate.queryForList("select to_char(d.DATA_DATE,'YYYY-MM-DD') as dataDate,d.DATA_HOUR as dataHour,sum(SYN_CONSIGN_CNT) - sum(NOPICK_CONSIGN_CNT) as pickCnt from DV_DW_KAD_LIVE_OVERVIEW d where d.DATA_DATE in (date'"+today+"',date'"+contrastday+"') and d.ordersource in (1,13,14,15,21) group by d.DATA_DATE,d.DATA_HOUR order by d.DATA_DATE,d.DATA_HOUR");
//	      return rows;
//	}
//	
//	/*
//	 * Brief：退款订单数
//	 */
//	public List<Map<String,Object>> getRefundOrderCnt(String today, String contrastday) {
//	      List<Map<String,Object>> rows = mJdbcTemplate.queryForList("select to_char(d.DATA_DATE,'YYYY-MM-DD') as dataDate,d.DATA_HOUR as dataHour,sum(REFUND_ORDER_CNT) as refundOrderCnt from DV_DW_KAD_LIVE_OVERVIEW d where d.DATA_DATE in (date'"+today+"',date'"+contrastday+"') and d.ordersource in (1,13,14,15,21) group by d.DATA_DATE,d.DATA_HOUR order by d.DATA_DATE,d.DATA_HOUR");
//	      return rows;
//	}
//	
//	/*
//	 * Brief：订单退款处理单数
//	 */
//	public List<Map<String,Object>> getRefundOrderHandleCnt(String today, String contrastday) {
//	      List<Map<String,Object>> rows = mJdbcTemplate.queryForList("select to_char(d.DATA_DATE,'YYYY-MM-DD') as dataDate,d.DATA_HOUR as dataHour,sum(DOWN_REFUND_CNT) as refundOrderHandleCnt from DV_DW_KAD_LIVE_OVERVIEW d where d.DATA_DATE in (date'"+today+"',date'"+contrastday+"') and d.ordersource in (1,13,14,15,21) group by d.DATA_DATE,d.DATA_HOUR order by d.DATA_DATE,d.DATA_HOUR");
//	      return rows;
//	}
//	
//	/*
//	 * Brief：某个渠道的访客数
//	 */
//	public List<Map<String,Object>> getChannelVisitCntLineChart(String ChannelName, String today, String contrastday) {
//	      List<Map<String,Object>> rows = mJdbcTemplate.queryForList("select to_char(d.DATA_DATE, 'YYYY-MM-DD') as dataDate,"
//	      				+ "d.DATA_HOUR as dataHour,"
//	      				+ "sum(VISIT_CNT) as visitCnt "
//	      				+ "from DV_DW_KAD_LIVE_OVERVIEW d "
//	      				+ "where d.DATA_DATE in (date'" + today + "', date'" + contrastday + "') "
//	      				+ "and UTM_MEDIUM = " + ChannelName
//	      				+ " and d.ordersource in (1,13,14,15,21) "
//	      				+ "group by d.DATA_DATE, d.DATA_HOUR "
//	      				+ "order by d.DATA_DATE, d.DATA_HOUR");
//	      return rows;
//	}
}


















